package com.liudadan.exceptionhandls;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
        @ExceptionHandler(NullPointerException.class)
        public String nullExceptionHandler(NullPointerException e){
            //记录日志
            System.out.println("GlobalExceptionHandler.nullExceptionHandler");
            return "空指针异常";
        }

    @ExceptionHandler(Exception.class)
    public String exceptionHandler(Exception e){
        //记录日志
        System.out.println("GlobalExceptionHandler.exceptionHandler");
        e.printStackTrace();
        return e.getMessage();
    }
}
